import imp
import os
import tornado.ioloop
import logging
from web.database import db
from web.dataimport import Importor, FileHandler

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    db.setup()
    path = os.path.dirname(os.path.realpath(__file__)) + '/web/datafiles'
    importor = Importor()
    importor.watch_dir(FileHandler(),path)

    ioloop = tornado.ioloop.IOLoop.current()
    try:
        ioloop.start()
    except KeyboardInterrupt:
        ioloop.stop()